/**
 * Created by nickleo on 15/3/27.
 */
function setClusterValue(li, btid) {
    var data = $(li).attr("data-cluster");
    $('#' + btid).attr("data-cluster", data);

    var namesvr = $(li).attr("data-namesvr");
    $('#' + btid).attr("data-namesvr", namesvr);
    $('#' + btid).html(data + " <span class=\"caret\"></span>")
}
function setBrokerConfigValue(li, btid) {
    var namesvr = $(li).attr("data-namesvr");
    var addr = $(li).attr("data-value");
    $('#broker-config-tab').attr("data-namesvr", namesvr);
    $('#broker-config-tab').attr("data-value", addr);
    $('#' + btid).html(addr + " <span class=\"caret\"></span>")
}

function upBrokerCfg() {

    var type = $('#broker-config-tab').attr("data-borker-select-type");
    var namesvr = $('#broker-config-tab').attr("data-namesvr");
    var typeValue = $('#broker-config-tab').attr("data-value");
    var key = null;
    var value = null;
    if (type == 'addr') {
        key = $('#basic-addon-addr-input-key').val();
        value = $('#basic-addon-addr-input-value').val();
    } else if (type == "cluster") {
        key = $('#basic-addon-cluster-input-key').val();
        value = $('#basic-addon-cluster-input-value').val();
    } else {
        alert(" what's Type ");
        return;
    }


    var url = "/manager/up_broker_cfg";
    var data = {
        'type': type,
        'namesvr': namesvr,
        'typeValue': typeValue,
        'key': key,
        'value': value
    };

    http_get(url, data, function (back) {
        alert(back.alert);
    });


}

function addTopic() {
    var clustername = $("#clusterid1").attr("data-cluster");
    var namesvr = $("#clusterid1").attr("data-namesvr");
    var addtopic = $("#add-topic-input").val();
    url = "/manager/add_topic?cluster=" + clustername + "&addtopic=" + addtopic + "&namesvr=" + namesvr
    http_get(url, null, function (data) {
        alert(data.alert);
    });

}

function addSubgroup() {
    var clustername = $("#cluster3").attr("data-cluster");
    var namesvr = $("#cluster3").attr("data-namesvr");

    var addtopic = $("#add-subgroup-input").val();
    url = "/manager/add_subgroup?cluster=" + clustername + "&subgroup=" + addtopic+ "&namesvr=" + namesvr
    http_get(url, null, function (data) {
        alert(data.alert);
    });

}

function delTopic() {
    var clustername = $("#clusterid2").attr("data-cluster");
    var namesvr = $("#clusterid2").attr("data-namesvr");
    var topic = $("#topicid1").attr("data-cluster");
    url = "/manager/del_topic?cluster=" + clustername + "&topic=" + topic+ "&namesvr=" + namesvr
    http_get(url, null, function (data) {
        alert(data.alert);
    });

}

function delSubgroup() {
    var clustername = $("#cluster4").attr("data-cluster");
    var addtopic = $("#consumer1").attr("data-cluster");
    var namesvr = $("#cluster4").attr("data-namesvr");

    url = "/manager/del_subgroup?cluster=" + clustername + "&subgroup=" + addtopic+ "&namesvr=" + namesvr
    http_get(url, null, function (data) {
        alert(data.alert);
    });

}